# -*- coding:UTF-8 -*-
import pygame
import os
import actor
class Hero(actor.Actor):
    '''
    英雄
    '''
    def __init__(self, x, y):
        '''
        英雄初始化
        :param rect:
        :param name:
        '''
        super(Hero, self).__init__(x, y, 'down', '伊瑞利亚')
        self.curr_dir = 'down'
        self.x_vel = 5
        self.y_vel = 5

    def set_imgae_path(self):
        '''
        设置图片路径
        :return:
        '''
        self.path = os.path.join('resource','graphics','actor',"player.png")

    def init_rect(self):
        '''
        初始化自身位置
        :return:
        '''
        self.curr_img_id = 0;
        self.set_rect()
        self.image_pos = {"left": self.left_rect, "right": self.right_rect, "up": self.up_rect,
            "down": self.down_rect }

    def set_rect(self):
        '''
        设置图片位置信息
        :return:
        '''
        self.left_rect = [pygame.Rect(0, 32, 32, 32), pygame.Rect(32, 32, 32, 32)]  # 角色左方向图片位置
        self.right_rect = [pygame.Rect(64, 32, 32, 32), pygame.Rect(96, 32, 32, 32)]  # 角色右方向图片位置
        self.down_rect = [pygame.Rect(64, 0, 32, 32), pygame.Rect(96, 0, 32, 32)]  # 角色右方向图片位置
        self.up_rect = [pygame.Rect(0, 0, 32, 32), pygame.Rect(32, 0, 32, 32)]  # 角色右方向图片位置

    def update(self):
        '''
        角色更新
        :return:
        '''
        # 移动图片位置
        self.curr_img_id += 1
        if self.curr_img_id >= len(self.image_pos[self.curr_dir]):
            self.curr_img_id = 0


    def action(self, keys, mouse):
        '''
        角色活动操作
        :param keys:
        :param mouse:
        :return:
        '''
        if keys[pygame.K_UP]:
            self.rect.top -= self.y_vel
            self.curr_dir = 'up'
        elif keys[pygame.K_DOWN]:
            self.rect.top += self.y_vel
            self.curr_dir = 'down'
        elif keys[pygame.K_LEFT]:
            self.rect.left -= self.x_vel
            self.curr_dir = 'left'
        elif keys[pygame.K_RIGHT]:
            self.rect.left += self.x_vel
            self.curr_dir = 'right'
